package com.zhike.b2b.dao;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;

public class JDBCExeCunt
{
  private String sqlString = "";
  private int startPage = 1;
  private int limit = 10;
  private int allcount = 0;
  private ResultSet rSet;

  public String getSqlString()
  {
    return this.sqlString;
  }

  public void setSqlString(String paramString)
  {
    this.sqlString = paramString;
  }
/*
  public ArrayList executeByJdbc()
    throws SQLException
  {
    if (this.sqlString.equals(""))
      throw new RuntimeException("未设置查询语句！");
    Statement st = DbConnect.getAutoConnection().createStatement();
    ResultSet rs = st.executeQuery(this.sqlString);
    ArrayList dmlist = getDataMata(rs);
    ArrayList data = new ArrayList();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    while (rs.next())
    {
      HashMap hm = new HashMap();
      for (int i = 0; i < dmlist.size(); i++)
      {
        HashMap dmhm = (HashMap)dmlist.get(i);
        if (dmhm.get("fileType").toString().equals("FLOAT"))
          hm.put(dmhm.get("filedName").toString(), String.valueOf(rs.getFloat(dmhm.get("filedName").toString())));
        else if (dmhm.get("fileType").toString().equals("INTEGER"))
          hm.put(dmhm.get("filedName").toString(), String.valueOf(rs.getInt(dmhm.get("filedName").toString())));
        else
          hm.put(dmhm.get("filedName").toString(), rs.getString(dmhm.get("filedName").toString()));
      }
      data.add(hm);
    }
    return data;
  }

  public ArrayList executeByJdbcByPage()
    throws SQLException
  {
    if (this.sqlString.equals(""))
      throw new RuntimeException("未设置查询语句！");
    Statement st = DbConnect.getAutoConnection().createStatement();
    ResultSet rs = st.executeQuery(this.sqlString + "limit " + (this.startPage - 1) * this.limit + " , " + this.limit);
    ArrayList dms = getDataMata(rs);
    ArrayList data = new ArrayList();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    while (rs.next())
    {
      HashMap hm = new HashMap();
      for (int i = 0; i < dms.size(); i++)
      {
        HashMap dmhm = (HashMap)dms.get(i);
        if (dmhm.get("fileType").toString().equals("FLOAT"))
          hm.put(dmhm.get("filedName").toString(), String.valueOf(rs.getFloat(dmhm.get("filedName").toString())));
        else if (dmhm.get("fileType").toString().equals("INTEGER"))
          hm.put(dmhm.get("filedName").toString(), String.valueOf(rs.getInt(dmhm.get("filedName").toString())));
        else
          hm.put(dmhm.get("filedName").toString(), rs.getString(dmhm.get("filedName").toString()));
      }
      data.add(hm);
    }
    rs.close();
    return data;
  }

  private int getDataCount()
    throws SQLException
  {
    if (this.sqlString.equals(""))
      throw new RuntimeException("未设置查询语句！");
    Statement st = DbConnect.getAutoConnection().createStatement(1004, 1008);
    ResultSet rs = st.executeQuery(this.sqlString);
    int i = 0;
    if (rs.last())
      i = rs.getRow();
    rs.close();
    return i;
  }
*/
  public ArrayList getDataMata(ResultSet paramResultSet)
    throws SQLException
  {
    ResultSetMetaData rsmd = paramResultSet.getMetaData();
    ArrayList data = new ArrayList();
    for (int i = 1; i <= rsmd.getColumnCount(); i++)
    {
      String str1 = rsmd.getColumnName(i);
      String str2 = rsmd.getColumnTypeName(i);
      HashMap localHashMap = new HashMap();
      localHashMap.put("filedName", str1);
      localHashMap.put("fileType", str2);
      data.add(localHashMap);
    }
    return data;
  }

  public int getStartPage()
  {
    return this.startPage;
  }

  public void setStartPage(int paramInt)
  {
    this.startPage = paramInt;
  }

  public void setLimit(int paramInt)
  {
    this.limit = paramInt;
  }

/*  public int getAllcount()
    throws SQLException
  {
    return getDataCount();
  }
*/
  public void setAllcount(int paramInt)
  {
    this.allcount = paramInt;
  }
}

